﻿/*  Francis Nino Seisei 
 *  ©2012 Francis Antonio Bolaños Arias.
 * 
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using Seisei.Global;

namespace Seisei.IO
{
    public class FileGuru
    {
        public static string[] GetDirectoryFileList(string Directory) {
            return System.IO.Directory.GetFileSystemEntries(Directory);
        }

        public static bool IsDirectory(string Path) {
            FileAttributes attr = File.GetAttributes(Path);
            if ((attr & FileAttributes.Directory) == FileAttributes.Directory) {
                return true;
            }
            return false;
        }

        public static void CreateNinoFilesFolders() {
            if (!Directory.Exists(Memory.WORKSPACE))
            {
                Directory.CreateDirectory(Memory.WORKSPACE);
            }
        }

        public static string OpenUTF8File(string FileName)
        {
            FileStream fs = File.Open(FileName, FileMode.Open, FileAccess.Read);
            StreamReader sr = new StreamReader(fs, System.Text.Encoding.UTF8);
            string content = sr.ReadToEnd();
            sr.Close();
            return content;
        }

        public static bool SaveUTF8File(string FileName, string Data) {
            if (File.Exists(FileName)) {
                File.Delete(FileName);
            }
            FileStream fs = File.Open(FileName, FileMode.OpenOrCreate, FileAccess.Write);
            StreamWriter sw = new StreamWriter(fs, System.Text.Encoding.UTF8);
            sw.WriteLine(Data);
            sw.Close();
            return true;
        }
    }
}
